import { AxiosError } from 'axios'

export type ErrorResponse = {
	status: number
}
class AxiosRequestError extends Error {
	data: ErrorResponse | undefined

	raw: AxiosError | undefined

	isUnAuthorized = false // 权限错误

	isServerError = false //服务器错误

	constructor(status: number, message: string, raw: AxiosError, data?: ErrorResponse) {
		super(message)
		this.data = data
		this.raw = raw
		this.isServerError = status >= 500
		this.isUnAuthorized = status === 401
		this.message = message || ''
	}
}

export default AxiosRequestError
